module.exports = (params) => {
	let url = params.url;	
	let method = params.method;	
	let header = params.header || {};	
	let data = params.data || {};
	//	请求方式 GET POST
	if	(method) {
		method = method.toUpperCase();	//	小写转大写
		if (method == "POST") {
			header = {"content-type":"application/x-www-form-urlencoded"}
		}
	}
	//	发起请求 加载动画
	if (!params.hideLoading){
		uni.showLoading({
			title:"加载中",
			mask:true
		})
	}

	try {
	    const value = uni.getStorageSync('userInfo');
	    if (value) {
			header = {"content-type":"application/x-www-form-urlencoded","token":value.token}
	    }
	} catch (e) {
	    // error
	}
	//	发起网络请求
	uni.request({
		url:url,
		method:method || "GET",
		header:header,
		data:data,
		dataType:"json",
		sslVerify:false,	//	是否验证ssl证书
		success: res => {
			//console.log('res------------',res)
			if	(res.statusCode && res.data.code != 200){
				//	api错误
				// uni.showModal({
				// 	content:res.data.msg
				// })
				uni.showToast({
				    title: res.data.msg || '未知错误'+res.statusCode,
				    duration: 2000,
					icon:'none'
				});
				if(res.data.code == 911){
					//console.log('重新登录')
					uni.removeStorage({
					    key: 'userInfo',
					    success: function (res) {
					        uni.redirectTo({
					            url: '/pages/Login/index'
					        });
					    },
						fail:function(err){
							
						}
					});
					
				}
				uni.stopPullDownRefresh();
				return;
			}
			typeof params.success == "function" && params.success(res.data);
		},
		fail: err => {
			uni.showToast({
			    title: err.msg || '未知错误',
			    duration: 2000,
				icon:'none'
			});
			typeof params.fail == "function" && params.fail(err.data);
		},
		complete: (e) => {
			//console.log("请求完成");
			uni.hideLoading()
			typeof params.complete == "function" && params.complete(e.data);
			return;
		}
	})
}